import java.io.Serializable;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;

/**
 * @author: knowno
 * @create: 2025-09-12 15:24
 * @Version 1.0
 **/
public class TestClass2 {
    public static void main(String[] args) throws ClassNotFoundException {

        //1 Class类型对象  对象.getClass()
//        Class cls1 = "string".getClass();
//
//        //2 类名.class
//        Class stringClass = String.class;
//
//        //3 接口名.class
//        Class<Serializable> serializableClass = Serializable.class;
//
//        //4 数组.class
//        Class intArrayClass = int[].class;

        //5 Class类中有一个静态方法 Class.forName
        Class<?> aClass = Class.forName("java.lang.String");

        System.out.println("*********getDeclaredFields 所有属性***************");
        //实例方法完成类内部成员获取
        Field[] declaredFields = aClass.getDeclaredFields();
        for (Field declaredField : declaredFields) {
            System.out.println(declaredField.getName());
        }

        System.out.println("***************getFields 公共属性****************");
        Field[] declaredFields1 = aClass.getFields();
        for (Field declaredField1 : declaredFields1) {
            System.out.println(declaredField1.getName());
        }

        System.out.println("*************getDeclaredMethods 所有方法************");
        Method[] declaredMethods = aClass.getDeclaredMethods();
        for (Method declaredMethod : declaredMethods) {
            System.out.println(declaredMethod.getName());
        }

        System.out.println("*************getDeclaredConstructors 所有构造方法************");
        Constructor<?>[] declaredConstructors = aClass.getDeclaredConstructors();
        for (Constructor<?> declaredConstructor : declaredConstructors) {
            System.out.println(declaredConstructor.getModifiers() + " " + declaredConstructor.getName());
        }

    }
}
